<?php

namespace App\Console\Commands;

use App\Modules\Order\Services\OrderService;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use voku\helper\HtmlDomParser;


class TestPay extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test_pay';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $rand_num = mt_rand(0,9999);
        $trade_no = date('YmdHis').str_pad($rand_num,4-strlen($rand_num),'0',STR_PAD_LEFT);
        $result = OrderService::alipay_pay($trade_no,'0.01');
        $res = json_decode(json_encode($result),true);
        $body = $res['body'];
        $ret = explode('&',$body);
        $return_arr = [];
        foreach ($ret as $key=>&$value) {
            $value = urldecode($value);
            list($k,$v) = explode('=',$value);
            $return_arr[$k] = $v;
        }
        var_dump($return_arr);
    }

}
